package com.gua.jbs.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gua.jbs.daoImpl.BaseDao;
import com.gua.jbs.daoImpl.IActionOnProductDao;
import com.gua.jbs.pojo.Jbspit;
import com.gua.jbs.utility.ApplicationConstant;
import com.gua.jbs.utility.QueryConstant;
import com.gua.jbs.utility.StringUtil;

public class ActionOnProductDao extends BaseDao implements IActionOnProductDao {

	@Override
	public List<Jbspit> getProductOnIdDao(String prodId) {
		// TODO Auto-generated method stub
		List<Jbspit> prodDetails=new ArrayList<Jbspit>();
		List lParams=new ArrayList();
		lParams.add(prodId);
		
		// Get the query by passing parameters
		String query = getQuery(QueryConstant.GET_PRODUCT_FOR_ID, lParams);				
		
		try {
			ResultSet rs = getResults(query);
			while (rs.next()) {
					 
				Jbspit objPit = new Jbspit();
				objPit.setProdId(String.valueOf(rs.getInt("ID")));
				objPit.setProdName(rs.getString("PROD_NAME"));
				objPit.setProdColor(rs.getString("COLOR"));
				objPit.setProdSize(String.valueOf(rs.getBigDecimal("SIZE")));
				objPit.setProdCode(rs.getString("BAR_CODE"));
				objPit.setProdType(rs.getString("TYPE"));
				objPit.setProdSubType(rs.getString("SUB_TYPE"));
				if(StringUtil.isNullOrEmpty(rs.getString("IMAGE")))
					objPit.setProdImage(rs.getString("IMAGE").replace("@", "//"));
				objPit.setExtrafield2((rs.getString("POLISH")));
				objPit.setProdPrice((rs.getString("PRICE")));
				objPit.setProdCost((rs.getString("COST")));
				objPit.setHrCode((rs.getString("HR_CODE")));
				objPit.setDesignCode((rs.getString("DESIGN_CODE")));
				objPit.setExtrafield1(rs.getString("DESCRIPTION"));
				objPit.setExtrafield3(rs.getString("STOCK"));
				objPit.setIsApproved(rs.getString("APPROVAL"));
				objPit.setCreateDate(rs.getDate("CREATED_DT"));
				prodDetails.add(objPit);
			} 
			return prodDetails;
		}
		catch (SQLException sqe) {
			return null;
		}
	}
}
